import { PageContainer } from '@ant-design/pro-layout';
import { message,Card,Button,Modal, Input,Radio } from 'antd';
import {UseSearch,UseTable} from '../../../components'
import React from 'react';
import QCProjectController from '@/services/QCProject/QCProjectController';
import DepartmentController from '@/services/System/DepartmentController';
import { getStr } from '@/components/function';
import Detail from '../detail'
const {confirm} = Modal
class Attribution extends React.Component {
    constructor(props) {
        super(props);
        let userInfo =JSON.parse(sessionStorage.getItem("userInfo"))
        let projectLevel = ''
        if(userInfo.targs.includes("市级")){
            projectLevel='市级'
        }
        if(userInfo.targs.includes("省级")){
            projectLevel='省级'
        }
        this.state = { 
            dataSource:[],
            freshen:false,
            datas:{},
            level:projectLevel,
            userInfo:userInfo,
            departmentList:[]
         };
    }
    componentDidMount(){
  
    }
 
    freshen=()=>{
        this.setState({freshen:!this.state.freshen})
    }
    handleSearch=(query)=>{
        this.setState({query})
        this.freshen()

    }
    reset=()=>{
        this.setState({query:{}})
        this.freshen()

    }
    getList=(query)=>{
        let {userInfo} = this.state
        if(userInfo.roleName.includes("市级部门负责人")){
            query.departmentId = userInfo.cityDepartmentCode
        }
        else if(userInfo.roleName.includes("省级部门负责人")){
            query.departmentId = userInfo.provinceDepartmentCode
        }
        else{
            query.departmentId = null
        }
        return QCProjectController.getAttributeList(query);
   

    }
    onCancel=()=>{
        this.setState({visibleNewProject:false,visibleResult:false})
        this.freshen()
    }
    toDetail=(rowData)=>{
        this.setState({
            rowData,
            visibleDetail:true
        })
    }
    toReview=(rowData)=>{
        this.setState({
            rowData,
            visibleReview:true
        })
    }
    onRef=(ref)=>{
        this.setState({
            modal:ref
        })
    }
    handleChange=(key,e)=>{
        let {datas} = this.state
        
        datas[key] = e.target?e.target.value :e
        this.setState({datas})
    }

    submit=()=>{
        let {datas,userInfo,rowData} = this.state
        let that = this
        datas.projectCode = rowData.projectCode
        datas.reviewStep =  "归口部门审批"
        datas.name = userInfo.name
        datas.userName = userInfo.userName
        console.log(datas)
        confirm({
            title:'提示',
            content:'确定要提交吗？',
            onOk(){
                QCProjectController.reviewSubmit(datas).then(r=>{
                    if(r&&r.data===2){
                        message.success('提交成功')
                        that.setState({visible:false})
                        
                        that.freshen()
                    }
                })
            }
        })
    }
    render() {
        const {rowData,departmentList,freshen,visibleDetail,query,visibleReview}=this.state
        const columns=[

            {title:'项目名称',dataIndex:'projectName',align:'center'},
            {title:'项目类别',dataIndex:'projectType',align:'center'},
            {title:'项目负责人',dataIndex:'projectLeaderName',align:'center'},
            {title:'现状调查',dataIndex:'statusSurvey',align:'center'},
            {title:'选题理由',dataIndex:'secectReason',align:'center',render:text=>getStr(text)},
            {title:'目标简述',dataIndex:'targetDescription',align:'center',render:text=>getStr(text)},
            {title:'审核步骤',dataIndex:'applyReviewStep',align:'center'},
            {title:'审核结果',dataIndex:'applyReviewResult',align:'center'},
            {title:'操作',align:'center',render:(text,rowData)=><div>
                {/* <Button onClick={this.toDetail.bind(this,rowData)} type={'primary'} style={{margin:5}}>查看详情</Button> */}
                {rowData&&rowData.applyReviewResult==="待审批"&&<Button onClick={this.toReview.bind(this,rowData)} type={'primary'}>审批</Button>}
                </div>},
        ]
        const buttonStyle={margin:5}
        const searchItem=[
            {name:'负责人姓名',keyName:'leaderUserName',valueType:'text'},
            {name:'项目名称',keyName:'projectName',valueType:'text'},
        ]
        return (
            <div>
                <Card>
                <UseSearch searchItem={searchItem} handleSearch={this.handleSearch} reset={this.reset} />  
                </Card>
                <Card>
                    <UseTable columns={columns} getData={this.getList} bordered rowKey={'projectCode'} refresh={freshen} query={query}/>
                </Card>
                {visibleReview&&<Modal
                visible={visibleReview}
                title={'审批'}
                onCancel={()=>this.setState({visibleReview:false})}
                onOk={this.submit}
                >
                    <div>
                        <strong>意见：</strong>
                        <Radio.Group onChange={this.handleChange.bind(this,'reviewResult')}>
                            <Radio value={"同意"} key={1}>同意</Radio>
                            <Radio value={"不同意"} key={2}>不同意</Radio>
                        </Radio.Group>
                    </div>
                    <div>
                        <strong style={{verticalAlign:"top"}}>备注：</strong>
                        <Input.TextArea placeholder="请输入" onChange={this.handleChange.bind(this,'reviewRemark')} style={{width:350}}></Input.TextArea>
                    </div>
                
                </Modal>}
                <Modal
                visible={visibleDetail}
                title={'项目详情'}
                onCancel={()=>this.setState({visibleDetail:false})}
                footer={false}
                width={"80%"}
                >
                    {visibleDetail&&<Detail rowData={rowData}/>}
                </Modal>
                
            </div>
        );
    }
}

export default Attribution;